/*
 * 
 * YCodaCode plugin 2.0
 * $Date: 2008-05-18 16:08:16 +0200 (dom, 18 mag 2008) $
 * $Rev: 92 $
 * @requires jQuery v1.2.3
 * @requires YCodaSlider v2.0
 * @requires jQuery Chili Plugin v1.9 
 * 
 * Copyright (c) 2008 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 * 
 */
YCodaSlider.Code = {
    init     : function(options, options_yslider)
    {
        
        options = jQuery.extend({
              }, options);
        var cnt = this.size();
        var j = this.parent();
        return this.each(
            function(nr)
            {
            	var that = this;
            	var js = jQuery("a",this);
                var j = jQuery(this).parent();
            	js.each(function(nr){
            	   var href = jQuery(this).attr("href");
            	   var self = this;
            	   var html = '<div class="yslider-panelwrapper" title="'+ jQuery(self).text() +'">';
            	   jQuery(self).wrap(html);
                   var panel = jQuery(self).parent();
                   //console.log(panel);
                   panel.empty();
                   jQuery.get(href, function(data){
            	   	   panel.html('<pre><code class="javascript">'+(YCodaSlider.Code.html_encode(data))+'</code></pre>');
            	   	   jQuery("code", panel).chili();
            	   });
            	   
            	});

            }
        );
    },
    html_encode : function (s) {
        var str = new String(s);
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
        str = str.replace(/"/g, "&quot;");
        return str;
    }
};
jQuery.fn.ycodacode = YCodaSlider.Code.init;